
import json
import unittest
from api.login import LoginAPI
from parameterized import parameterized

def build_data():
    json_file = "../data/login.json"
    test_data = []
    with open(json_file,encoding="utf-8") as f:
        json_data = json.load(f)
        for case_data in json_data:
            login_data = case_data.get("login_data")
            status_code = case_data.get("status_code")
            success = case_data.get("success")
            code = case_data.get("code")
            message = case_data.get("message")
            test_data.append((login_data,status_code,success,code,message))
            # print("test_data = {}".format((login_data,status_code,success,code,message)))
        return test_data

class TestLogin(unittest.TestCase):
    def setUp(self):
        self.login_api = LoginAPI()

    @parameterized.expand(build_data)
    def test01_login(self,login_data,status_code,success,code,message):
        print(login_data)
        response = self.login_api.login(login_data)
        print(response.json())
        # 断言
        # self.assertEqual(status_code, response.status_code)
        # self.assertEqual(success, response.json().get("success"))
        # self.assertEqual(code, response.json().get("code"))
        # self.assertIn(message, response.json().get("message"))